<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">取消下载</button>
    <script>
        let isCancel = false
        const handleCancel = () => {
            if (isCancel) return new Promise((resolve, reject) => {
                reject('已取消下载')
            })
        }

        const lodash = () => {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve('文件下载成功')
                }, 5000)
            })
        }
        const handleDown = () => {
            Promise.race([lodash()]).then(res => {
                console.log(res, 'res')
            }).catch(err => {
                console.log(err, 'err')
            })
        }
        handleDown()


        const btn = document.getElementById('btn')
        btn.addEventListener('click', () => {
            isCancel = true
        })
        const promise = new Promise((resolve, reject) => {
            console.log('00000')
            resolve('22222')
            reject('err')
        })
        promise.then((success) => {
            //成功
            console.log(success)
            // throw 'err33333'
            return success
        }, (err) => {
            //失败
            console.log(err)
        }).catch(err => {
            console.log(err, ':err0')
        })
            .then((success) => {
                console.log(success, ':success')
                throw 'abc'
            }, (err) => {
                console.log(err)
            }).catch(err => {
                console.log(err, 'err')
            })
        console.log('11111')
    </script>
</body>

</html>